package com.ruoyi.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

public class MyHttpUtils {
    private static final Logger log = LoggerFactory.getLogger(MyHttpUtils.class);

    public void printHeaders(HttpServletRequest request) {
        StringBuilder headerInfo = new StringBuilder();
        // Get all header names
        java.util.Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            headerInfo.append(headerName).append(": ");
            // Get all values for the current header
            java.util.Enumeration<String> headerValues = request.getHeaders(headerName);
            while (headerValues.hasMoreElements()) {
                headerInfo.append(headerValues.nextElement());
                if (headerValues.hasMoreElements()) {
                    headerInfo.append(", "); // If there are multiple values, separate them with a comma
                }
            }

            headerInfo.append("\n");
        }
        log.info(headerInfo.toString());
    }
}
